-
Notifications
You must be signed in to change notification settings - Fork 5.3k
fix(ulog): 修复异步 ulog 空唤醒与通知丢失问题,并优化告警输出 #11183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-02-12 09:03 CST)
📝 Review Instructions
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR targets RT-Thread’s ulog async output path to reduce empty wakeups and avoid losing wakeup notifications, and it refactors repeated “warn once” diagnostics into a helper.
Changes:
- Add
ulog_warn_once()and refactor several “print only once” warnings to use it. - In async raw logging, release the notification semaphore only when data is actually written, and emit a one-time warning on partial writes.
- Remove the semaphore reset in
ulog_async_waiting_log()to avoid clearing pending notifications.
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
在此前的异步 ulog 实现中,存在以下问题:
在调用
rt_ringbuffer_put()之后,无论是否实际写入数据,都会释放通知信号量。当 ringbuffer 已满、写入长度为 0 时,
消费线程仍会被唤醒,导致空唤醒和不必要的调度开销。
ulog_async_waiting_log()在等待信号量前对其进行了 reset。如果生产者在 reset 之前刚好释放了信号量,该通知可能被清除,
从而导致唤醒丢失,异步日志处理被延迟。
此外,ulog 中存在多处重复的“只打印一次”警告逻辑,缺乏统一说明,
在高并发场景下也可能引发理解歧义。
你的解决方案是什么 (what is your solution)
仅在 ringbuffer 实际写入数据(
put_len > 0)后才释放通知信号量,确保每次唤醒都对应有效的日志数据,避免空唤醒。
移除
ulog_async_waiting_log()中对信号量的 reset,避免清除已有通知, 防止唤醒丢失。在异步 buffer 饱和导致部分写入时,输出一次性(best-effort)的告警提示。
新增轻量级
ulog_warn_once()辅助函数, 统一告警输出逻辑。Commit 1:整理并统一告警输出逻辑,仅涉及诊断信息,不影响异步唤醒语义。
Commit 2:修复异步 ulog 的唤醒与通知处理逻辑,避免空唤醒和通知丢失
请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up